<?php
require_once 'BaseController.php';

/**
 * 社宅物件リクエスト検索クラス<br />
 *
 * @package    apamanshop
 * @author     SS山本
 * @copyright  コピーライト(要確認)
 */
class Search_HouzinrequestsearchController extends Search_BaseController
{
	public function indexAction()
	{
		if ((empty($this->_params['ComId']) && $this->_params['ComId'] != '0') || (empty($this->_params['ComGenruFlg']) && $this->_params['ComGenruFlg'] != '0')) {
			// 法人CDが無い場合、ログイン画面へリダイレクト
			Apm_Util::redirect('/asnnet/login/?loginError=1');
			exit();
		}

		/*
		 * 基本情報設定
		 */
		// 検索区分
		$this->setSearchKbn(Apm_Config_Search::SRHKBN_BUKENREQUEST_SYATAKU, "houzinrequestsearch");
		// 検索サブ区分
		$this->_data['srhtype_jyusyo']   = Apm_Config_Search::SRHTYPE_JYUSYO;
		$this->_data['srhtype_enseneki'] = Apm_Config_Search::SRHTYPE_ENSENEKI;

        // 以下、検索画面によって条件分けする。
        // 都道府県検索画面の出力(初期呼び出し時)
		if (! $this->_model_common->checkvalue($this->_params, "PrefCd"))
    	{

			// H1のタイトル
			$this->_data['h1_title'] = 'ご希望の都道府県を選択してください。';
			$this->_main_helper = $this->_todohuken_houzinrequest_helper;
    	}
		//政令指定都市・市区検索画面の出力（市区町村選択画面で検索時）
		else if ( $this->_model_common->returnValue($this->_params,"SrhType") == Apm_Config_Search::SRHTYPE_JYUSYO
		         && ! $this->_model_common->checkvalue($this->_params, "CityCd") && $this->_model_common->checkvalue($this->_params, "SiteitosiCd") )
		{

            // 市区町村モデル
		    $this->_model_sikucyoson = new Search_Model_Selsikucyoson();

			// H1のタイトル
			$this->_data['h1_title'] = 'ご希望の政令指定都市を選択してください。';

			$this->_data['selcity'] = array();
			$this->_data['selcity'] = $this->_model_sikucyoson->getSiteiShikuData($this->_params, "0");

			// 表示用データに変換
			$this->_model_sikucyoson->convertShikucyosonData($this->_data);
			$this->_data['selSiteitosiKbn'] = "1";

			$this->_main_helper = $this->_shikucyoson_houzinrequest_helper;
		}
		// 市区町村検索画面の出力（都道府県検索画面で検索時）
		else if ( $this->_model_common->returnValue($this->_params,"SrhType") == Apm_Config_Search::SRHTYPE_JYUSYO
		         && ! $this->_model_common->checkvalue($this->_params, "CityCd") )
		{

            // 市区町村モデル
		    $this->_model_sikucyoson = new Search_Model_Selsikucyoson();

			// H1のタイトル
			$this->_data['h1_title'] = 'ご希望の市区町村を選択してください。';

			$this->_data['selcity'] = array();
			$this->_data['selcity'] = $this->_model_sikucyoson->getRequestShikucyosonData($this->_params);
	        // 表示用データに変換
        	$this->_model_sikucyoson->convertShikucyosonData($this->_data);
			// 不要なパラメータを削除
			if (isset($this->_params['SelTownKbn'])) {
				unset($this->_params['SelTownKbn']);
			}

			$this->_main_helper = $this->_shikucyoson_houzinrequest_helper;
		}
		// 町名検索画面の出力（市区町村検索画面で検索時）
		else if ( $this->_model_common->returnValue($this->_params,"SrhType") == Apm_Config_Search::SRHTYPE_JYUSYO
		         && ! $this->_model_common->checkvalue($this->_params, "TownCd") && $this->_params["SelTownKbn"] == "1" )
		{

		    // 町名モデル
		   $this->_model_cyo = new Search_Model_Selcyo();

			// H1のタイトル
			$this->_data['h1_title'] = 'ご希望の町名を選択してください。';

			$this->_data['seltown'] = array();
			$this->_data['seltown'] = $this->_model_cyo->getRequestCyoData($this->_params);
	        // 表示用データに変換
        	$this->_model_cyo->convertCyoData($this->_data);

			$this->_main_helper = $this->_cyo_houzinrequest_helper;
		}
        // 沿線検索画面の出力（都道府県検索画面で検索時）
		else if ( $this->_model_common->returnValue($this->_params,"SrhType") == Apm_Config_Search::SRHTYPE_ENSENEKI
		         && ! $this->_model_common->checkvalue($this->_params, "RailCd") )
		{

            // 沿線モデル
		    $this->_model_ensen = new Search_Model_Selensen();

			// H1のタイトル
			$this->_data['h1_title'] = 'ご希望の沿線を選択してください。';

			$this->_data['selensen'] = array();
			$this->_data['selensen'] = $this->_model_ensen->getRequestEnsenDataByMulti($this->_params);

			// 表示用データに変換
			$this->_model_ensen->convertEnsenDataByMulti($this->_data);

			$this->_main_helper = $this->_ensen_houzinrequest_helper;
		}
		// 駅検索画面の出力（沿線検索画面で検索時）
		else if ( $this->_model_common->returnValue($this->_params,"SrhType") == Apm_Config_Search::SRHTYPE_ENSENEKI
		         && ! $this->_model_common->checkvalue($this->_params, "StCd") )
		{

		    // 駅モデル
		    $this->_model_eki = new Search_Model_Seleki();

			// H1のタイトル
			$this->_data['h1_title'] = 'ご希望の駅を選択してください。';

	        $this->_data['seleki'] = array();
			$this->_data['seleki'] = $this->_model_eki->getRequestEkiData($this->_params);

			// 表示用データに変換
			$this->_model_eki->convertEkiData($this->_data);

			$this->_main_helper = $this->_eki_houzinrequest_helper;

		}
		// 条件選択
		else if (
					(  $this->_model_common->returnValue($this->_params,"SrhType") == Apm_Config_Search::SRHTYPE_JYUSYO
					&& $this->_model_common->checkvalue($this->_params, "CityCd")
					&& ($this->_params["SelTownKbn"] == "0"
						|| ($this->_model_common->checkvalue($this->_params, "TownCd") && $this->_params["SelTownKbn"] == "1"))
					)
					||
					(  $this->_model_common->returnValue($this->_params,"SrhType") == Apm_Config_Search::SRHTYPE_ENSENEKI
					&& $this->_model_common->checkvalue($this->_params, "RailCd")
					&& $this->_model_common->checkvalue($this->_params, "StCd")
					)
				)
		{
			//DB問合せ：ご希望の検索条件一覧取得
		    $loader = new Zend_Application_Module_Autoloader(array(
				'namespace' => 'Rstobi',
				'basePath' => APPLICATION_PATH . '/modules/rstobi',
			));
			$this->_model = new Rstobi_Model_SearchDisplay();
	
			//検索条件（地域・沿線）の反映
			$this->_model->getSearchConditionChiikiEnsen($this->_params,$this->_data);
	
			//検索条件（基本条件）の反映
			$this->_model->getSearchConditionKihon($this->_params,$this->_data);
			//検索条件（こだわり条件）の反映
			$this->_model->getSearchConditionKodawari($this->_params,$this->_data);

			// 社宅控除率
			if($this->_model_common->checkvalue($this->_params, "ComId"))
			{
				$this->_model_rstobi_common = new Rstobi_Model_Common();
				$shatakuKoujyoritsu = $this->_model_rstobi_common->getShatakuKoujyoritsu($this->_params);
				$this->_data['shatakuKoujyoritsu'] = (100- floor( $shatakuKoujyoritsu )) / 100 * 1.05;
			}

			// H1のタイトル
			$this->_data['h1_title'] = 'ご希望の条件を指定してください。';

			// Hiddenタグ生成
			$hidden = array();
			$hidden['SrhKbn']      = $this->_params['SrhKbn'];
			$hidden['SrhType']     = $this->_params['SrhType'];
			$hidden['first_check'] = $this->_params['first_check'];
			$hidden['PrefCd']      = $this->_params['PrefCd'];
			if ($this->_model_common->checkvalue($this->_params, "CityCd")) {
				$hidden['CityCd']      = $this->_params['CityCd'];
				$hidden['SelTownKbn']  = $this->_params['SelTownKbn'];
			}
			if ($this->_model_common->checkvalue($this->_params, "TownCd")) {
				$hidden['TownCd']      = $this->_params['TownCd'];
			}
			if ($this->_model_common->checkvalue($this->_params, "RailCd")) {
				$hidden['RailCd']      = $this->_params['RailCd'];
			}
			if ($this->_model_common->checkvalue($this->_params, "StCd")) {
				$hidden['StCd']        = $this->_params['StCd'];
			}
			$hidden['ComGenruFlg']    = $this->_params['ComGenruFlg'];
			$hidden['strComName']     = $this->_params['strComName'];
			$hidden['BrowserTitle']   = $this->_params['BrowserTitle'];
			$hidden['ComId']          = $this->_params['ComId'];
			$hidden['KoujyoRitsu']    = $this->_params['KoujyoRitsu'];
			//$hidden['ExplanationFlg'] = $this->_params['ExplanationFlg'];
			$hidden['RequestFlg']     = $this->_params['RequestFlg'];
			//$hidden['strRequestFlg']  = $this->_params['strRequestFlg'];
			$hidden['EtcFlg']         = $this->_params['EtcFlg'];
			$this->_data['ReqHiddenTag'] = Apm_Util::generateHiddenTag($hidden);

			// 基本条件・こだわり条件の取得
			$this->_disabledLeftPanel = false;

			$this->_main_helper = $this->_selbasic_houzin_helper;
		}
// TODO 処理内容未決定
//		//町名検索画面で検索時
//		else
//		{
//        	$this->_data['main_block']  = $this->_main_helper->getBlock($this->_data);
//		}

		// 法人サイト共通設定
		$this->setAsnnetCommon();
//		$this->_data['ComGenruFlg'] = $this->_params['ComGenruFlg'];
//		$this->_data['strComName'] = $this->_params['strComName'];
//		$this->_data['BrowserTitle'] = $this->_params['BrowserTitle'];
//		$this->_data['ComId'] = $this->_params['ComId'];
//		$this->_data['KoujyoRitsu'] = $this->_params['KoujyoRitsu'];
//		//$this->_data['ExplanationFlg'] = $this->_params['ExplanationFlg'];
//		$this->_data['RequestFlg'] = $this->_params['RequestFlg'];
//		$this->_data['EtcFlg'] = $this->_params['EtcFlg'];

		$this->setXPassThroutgh();

        // 表示
		$this->_display_path = APPLICATION_PATH . '/modules/search/views/scripts/houzinrequestsearch.tpl';

	}
	

}
?>